package com.isunland.managesystem.adapter;

import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseButterKnifeAdapter;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.OrderSaleCollectOriginal.OrderSaleCollectContent;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.ArrayList;

public class OrderSaleCollectAdapter extends BaseButterKnifeAdapter<OrderSaleCollectContent> {

  public OrderSaleCollectAdapter(BaseVolleyActivity context,
      ArrayList<OrderSaleCollectContent> objects) {
    super(context, objects);
  }

  @Override protected int setLayoutId() {
    return R.layout.adapter_order_collect;
  }

  @NonNull @Override protected BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override
  protected void initView(OrderSaleCollectContent item, BaseViewHolder baseHolder, int position) {
    ViewHolder holder = (ViewHolder) baseHolder;

    holder.tvTitle.setText(
        MyStringUtil.connect(item.getMaterialName(), "(", item.getInbillCode(), ")　—",
            item.getMtype()));
    holder.tvContent.setText(item.getCustomerName());//客户单位
    holder.tvContent.setVisibility(
        TextUtils.isEmpty(item.getCustomerName()) ? View.GONE : View.VISIBLE);
    if ("01".equals(item.getStatisticType())) {
      //出库  申请,实际
      holder.tvApplyNum.setText(
          MyStringUtil.connect(context.getResources().getString(R.string.apply_outNumber),
              item.getInoroutNumber(), item.getMunit()));
      holder.tvRealNum.setText(
          MyStringUtil.connect(context.getResources().getString(R.string.real_outNumber),
              item.getActualInoroutNumber(), item.getMunit()));
    }
    if ("02".equals(item.getStatisticType())) {
      //入库 申请,实际
      holder.tvApplyNum.setText(
          MyStringUtil.connect(context.getResources().getString(R.string.apply_inNumber),
              item.getInoroutNumber(), item.getMunit()));
      holder.tvRealNum.setText(
          MyStringUtil.connect(context.getResources().getString(R.string.real_inNumber),
              item.getActualInoroutNumber(), item.getMunit()));
    }
    holder.tvRegData.setText(
        MyStringUtil.connect(item.getAppManName(), "  ", item.getAppDate()));//业务员,申请时间
  }

  protected class ViewHolder extends BaseViewHolder {
    @BindView(R.id.tv_title) TextView tvTitle;
    @BindView(R.id.tv_content) TextView tvContent;
    @BindView(R.id.tv_applyNum) TextView tvApplyNum;
    @BindView(R.id.tv_realNum) TextView tvRealNum;
    @BindView(R.id.tv_regData) TextView tvRegData;

    ViewHolder(View view) {
      super(view);
      ButterKnife.bind(this, view);
    }
  }
}
